package com.itserver.controller.sysUtilsController;


import com.itserver.pojo.PageResult;
import com.itserver.pojo.Result;
import com.itserver.pojo.sysUtils.FormItem;
import com.itserver.pojo.sysUtils.QueryFormItem;
import com.itserver.service.sysUtils.FormCreateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sysUtils/formCreate")
public class FormCreate {
    @Autowired
    private FormCreateService formCreateService;
    @GetMapping
    public Result list(QueryFormItem queryFormItem){
        log.info("查询表单列表");
        PageResult<FormItem> pageResult = formCreateService.list(queryFormItem);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result add(@RequestBody FormItem formItem){
        log.info("添加表单");
        formCreateService.add(formItem);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody FormItem formItem){
        log.info("更新表单");
        formCreateService.update(formItem);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除表单");
        formCreateService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{formId}")
    public Result getById(@PathVariable Object formId){
        log.info("查询表单");
        FormItem formItem = formCreateService.getById(formId);
        return Result.success(formItem);
    }
}
